package de.dpunkt.myaktion.model;

import javax.persistence.Embeddable;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

@Embeddable
public class FormConfig {

	@NotNull
	@Pattern(regexp="[a-fA-F0-9]{6}", message="{FormConfig.bgColor.Pattern}")
	private String bgColor;
	
	@NotNull
	@Pattern(regexp="[a-fA-F0-9]{6}", message="{FormConfig.textColor.Pattern}")
	private String textColor;
	
	@NotNull
	@Size(min=5, max=40, message="{FormConfig.titel.Size}")
	private String titel;
	
	public FormConfig() {
		this("000000", "FFFFFF", "Geld spenden");
	}
	public FormConfig(String bgColor, String textColor, String titel) {
		this.bgColor = bgColor;
		this.textColor = textColor;
		this.titel = titel;
	}
	public String getBgColor() {
		return bgColor;
	}
	public void setBgColor(String bgColor) {
		this.bgColor = bgColor;
	}
	public String getTextColor() {
		return textColor;
	}
	public void setTextColor(String textColor) {
		this.textColor = textColor;
	}
	public String getTitel() {
		return titel;
	}
	public void setTitel(String titel) {
		this.titel = titel;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((bgColor == null) ? 0 : bgColor.hashCode());
		result = prime * result
				+ ((textColor == null) ? 0 : textColor.hashCode());
		result = prime * result + ((titel == null) ? 0 : titel.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		FormConfig other = (FormConfig) obj;
		if (bgColor == null) {
			if (other.bgColor != null)
				return false;
		} else if (!bgColor.equals(other.bgColor))
			return false;
		if (textColor == null) {
			if (other.textColor != null)
				return false;
		} else if (!textColor.equals(other.textColor))
			return false;
		if (titel == null) {
			if (other.titel != null)
				return false;
		} else if (!titel.equals(other.titel))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		return "FormConfig [bgColor=" + bgColor + ", textColor=" + textColor
				+ ", titel=" + titel + "]";
	}
}
